#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
class MaxQueue
{
public:
    vector<int> que;
    int front, rear, maxval, len, base;
    MaxQueue(int front = 0, int rear = -1, int maxval = -1, int len = 0, int base = 3000) : front(front), rear(rear), maxval(maxval), len(len), base(base)
    {
        que.resize(base);
    };
    int max_value()
    {
        return maxval;
    }

    void push_back(int value)
    {
        rear = (rear + 1);
        que[rear] = value;
        maxval = max(maxval, value);
        len++;
    }
    int pop_front()
    {
        if (len == 0)
        {
            maxval = -1;
            return -1;
        }
        if (que[front] == maxval)
        {
            int index = (front + 1);
            maxval = que[index];
            while (index != rear)
            {
                maxval = max(maxval, que[index]);
                index = (index + 1) % base;
            }
        }
        int ret = que[front];
        front = (front + 1);
        len--;
        if (len == 0)
            maxval = -1;
        return ret;
    }
};

/**
 * Your MaxQueue object will be instantiated and called as such:
 * MaxQueue* obj = new MaxQueue();
 * int param_1 = obj->max_value();
 * obj->push_back(value);
 * int param_3 = obj->pop_front();
 */